<?php namespace WoXuanWang\Settings\Controllers;

use WoXuanWang\Settings\Requests\FollowSettingRequest;
use WoXuanWang\ActionLog\Repositories\ActionLogRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use WoXuanWang\Settings\Repositories\SettingsRepository;
use zgldh\Scaffold\AppBaseController;

class SettingsController extends AppBaseController
{

    public function __construct(SettingsRepository $settingRepo)
    {
        $this->repository = $settingRepo;
        $this->middleware("auth");
        $this->middleware("role:admin");
    }

    public function follow(FollowSettingRequest $request)
    {
        $gridId = $request->input('grid');
        $settingData = $request->getSettingData();
        $settingKey = $this->repository->getDashboardSettingKey();
        $result = $this->repository->setDashboardGrid($gridId, $settingData, $settingKey);
        ActionLogRepository::log("编辑", "总览单元格设置(setting)" . $gridId, \Auth::user());
        return $this->sendResponse($result, 'follow successfully.');
    }

}
